package com.edu.controller.front.order;

import com.edu.entity.Order;
import com.edu.entity.User;
import com.edu.service.ordertab.OrderService;
import com.edu.service.ordertab.OrderServiceImpl;
import com.edu.utils.GetLoginUser;
import com.edu.utils.ParamFormat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author ZCN
 * @version 1.0
 * @date 2021/11/25 15:26
 */
@WebServlet("/front/querymyorder")
public class QueryMyOrderServlet extends HttpServlet {
    private OrderService orderService = new OrderServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            ParamFormat.format(req, resp);
            User user = GetLoginUser.getUser(req);
            // 未支付
            List<Order> notpayorders = orderService.findnotpayByUserid(user.getId());
            // 未上菜
            List<Order> notserveorders = orderService.findnotserveByUserid(user.getId());
            // 已完成
            List<Order> successorders = orderService.findsuccessByUserid(user.getId());

            // 已取消
            List<Order> cancelorders = orderService.findcancelByUserid(user.getId());

            req.setAttribute("notpayorders",notpayorders);
            req.setAttribute("notserveorders",notserveorders);
            req.setAttribute("successorders",successorders);
            req.setAttribute("cancelorders",cancelorders);

            req.getRequestDispatcher("/front/myorder.jsp").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
